<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>返回上一个错误</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.oci-define-by-name.html">oci_define_by_name</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.oci-execute.html">oci_execute</a></div>
 <div class="up"><a href="ref.oci8.html">OCI8 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.oci-error" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">oci_error</h1>
  <p class="verinfo">(PHP 5, PECL OCI8 &gt;= 1.1.0)</p><p class="refpurpose"><span class="refname">oci_error</span> &mdash; <span class="dc-title">返回上一个错误</span></p>

 </div>
 <div class="refsect1 unknown-unknown-seealsq" id="refsect1-function.oci-error-unknown-unknown-seealsq">
  <h3 class="title">说明</h3>
   <div class="methodsynopsis dc-description">
    <span class="type">array</span> <span class="methodname"><strong>oci_error</strong></span>
     ([ <span class="methodparam"><span class="type">resource</span> <code class="parameter">$source</code></span>
   ] )</div>

  <p class="para rdfs-comment">
   对于大多数错误，参数是最适合的资源句柄。对于
   <span class="function"><a href="function.oci-connect.html" class="function">oci_connect()</a></span>，<span class="function"><a href="function.oci-new-connect.html" class="function">oci_new_connect()</a></span>
   或 <span class="function"><a href="function.oci-pconnect.html" class="function">oci_pconnect()</a></span>
   的连接错误，不要传递参数。如果没有发现错误，<span class="function"><strong>oci_error()</strong></span>
   返回 <strong><code>FALSE</code></strong>。<span class="function"><strong>oci_error()</strong></span>
   以一个关联数组返回错误。在此数组中，<em>code</em>
   是 oracle 错误代码而 <em>message</em> 是 oracle 的错误字符串。
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <strong>自 PHP 4.3 起</strong><br />
   <p class="para">
    <em>offset</em> 和 <em>sqltext</em>
    也包括在返回的数组中，用来指出错误发生的位置以及造成错误的原始的 SQL 文本。
   </p>
  </p></blockquote>
  <p class="para">
   <div class="example" id="example-1943">
    <p><strong>Example #1 连接错误后显示 Oracle 错误信息</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
$conn&nbsp;=&nbsp;@oci_connect("scott",&nbsp;"tiger",&nbsp;"mydb");<br />if&nbsp;(!$conn)&nbsp;{<br />&nbsp;&nbsp;$e&nbsp;=&nbsp;oci_error();&nbsp;&nbsp;&nbsp;//&nbsp;For&nbsp;oci_connect&nbsp;errors&nbsp;pass&nbsp;no&nbsp;handle<br />&nbsp;&nbsp;echo&nbsp;htmlentities($e['message']);<br />}</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-1944">
    <p><strong>Example #2 语法解析错误后显示 Oracle 错误信息</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
$stmt&nbsp;=&nbsp;@oci_parse($conn,&nbsp;"select&nbsp;'&nbsp;from&nbsp;dual");&nbsp;&nbsp;//&nbsp;note&nbsp;mismatched&nbsp;quote<br />if&nbsp;(!$stmt)&nbsp;{<br />&nbsp;&nbsp;$e&nbsp;=&nbsp;oci_error($conn);&nbsp;&nbsp;//&nbsp;For&nbsp;oci_parse&nbsp;errors&nbsp;pass&nbsp;the&nbsp;connection&nbsp;handle<br />&nbsp;&nbsp;echo&nbsp;htmlentities($e['message']);<br />}</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-1945">
    <p><strong>Example #3 执行错误后显示 Oracle 错误信息和出错的语句</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
$r&nbsp;=&nbsp;oci_execute($stmt);<br />if&nbsp;(!$r)&nbsp;{<br />&nbsp;&nbsp;$e&nbsp;=&nbsp;oci_error($stmt);&nbsp;//&nbsp;For&nbsp;oci_execute&nbsp;errors&nbsp;pass&nbsp;the&nbsp;statementhandle<br />&nbsp;&nbsp;echo&nbsp;htmlentities($e['message']);<br />&nbsp;&nbsp;echo&nbsp;"&lt;pre&gt;";<br />&nbsp;&nbsp;echo&nbsp;htmlentities($e['sqltext']);<br />&nbsp;&nbsp;printf("\n%".($e['offset']+1)."s",&nbsp;"^");<br />&nbsp;&nbsp;echo&nbsp;"&lt;/pre&gt;";<br />}</span>
</code></div>
    </div>

   </div>
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    在 PHP 5.0.0 之前的版本必须使用 <span class="function"><a href="function.ocierror.html" class="function">ocierror()</a></span>
    替代本函数。该函数名仍然可用，为向下兼容作为
    <span class="function"><strong>oci_error()</strong></span> 的别名。不过其已被废弃，不推荐使用。
   </p>
  </p></blockquote>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.oci-define-by-name.html">oci_define_by_name</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.oci-execute.html">oci_execute</a></div>
 <div class="up"><a href="ref.oci8.html">OCI8 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
